/**
 * 左边数组结构
 * **/
import React, {Component} from 'react';
import {connect} from 'dva';
import Container from '../../../../components/Container'
import MyTable from '../../../../components/MyTable'
import config from '../../../../config'
import MyIcon from '../../../../components/MyIcon'
import MyModel from '../../../../components/MyModel'
import PublicService from '../../../../services/PublicService'

class Right extends Component {
  addHandle() {
    this.props.dispatch({type:'pointManage/saveInfo',payload:{isVisible:true}})
  }

  rowSelectChange(selectedRowKeys, selectedRows){
   console.log(selectedRowKeys, selectedRows);
   this.props.dispatch({type:'pointManage/saveInfo',payload:{selectedRows}})
  }
  modalCancel() {
    this.props.dispatch({type: 'stationRule/saveInfo', payload: {isVisibleDevice: false,initDataDevice:{}}})
  }

  modalSave(params) {
    console.log(params);
    params.basicType = params.basicType.key;
    params.deviceType = params.deviceType.key;
    params.areaId = params.areaId.key;
    params.tagType = params.tagType.key;
    params.installTime = moment(params.installTime).unix() * 1000;
    params.operationTime = moment(params.operationTime).unix() * 1000;
    this.props.dispatch({type: 'stationRule/submitDevice', payload: {params}})
  }


  deleteHandle() {
    console.log('删除');
    this.props.dispatch({type: 'stationRule/deleteDeviceHandle'})
  }

  onChangePage(page, size) {
    this.props.dispatch({type: 'stationRule/pageChangeDeviceHandle', payload: {pageDevice: page, sizeDevice: size}})
  }
  render() {
    let t = this;
    let columns = [
      {
        dataIndex: 'pointName',
        title: '测点名称',
        key: 'pointName',
        width: 150,
      },
      {
        dataIndex: 'observeNameOrParameterType',
        title: '观察项/参考类型',
        key: 'observeNameOrParameterType',
        width: 150,
      },
      {
        dataIndex: 'referStandard',
        title: '参考标准',
        key: 'referStandard',
        width: 150,
      },
      {
        dataIndex: 'handle',
        title: '操作',
        key: 'handle',
        width: 150,
        render(text, record) {
          return (
            <div>
              <MyIcon type="icon-zengjia1" style={{fontSize: '12px', color: '#16b8be'}}/> | <MyIcon type="icon-zengjia1"
                                                                                                    style={{
                                                                                                      fontSize: '12px',
                                                                                                      color: '#16b8be'
                                                                                                    }}/>
            </div>
          )
        }
      },
    ];
    let dataSource = [
      {
        key: '1'
      },
      {
        key: '2'
      },
      {
        key: '3'
      },
      {
        key: '4'
      },
      {
        key: '5'
      },
      {
        key: '6'
      },
      {
        key: '7'
      },
      {
        key: '8'
      },
      {
        key: '9'
      },
      {
        key: '10'
      },
      {
        key: '11'
      },
      {
        key: '12'
      },
      {
        key: '13'
      },
      {
        key: '14'
      },
      {
        key: '15'
      },
      {
        key: '16'
      },
    ];
    let title = <div className="xnw-right-title">
      <span className="xnw-right-title1">1# 风机</span> <span>测量标准配置</span>
    </div>;
    let height = document.body.clientHeight;
    const rowSelection = {
      onChange: t.rowSelectChange.bind(t)
    };
    return (
      <div className="xnw-right">
        <Container
          containerTitle={title}
          addBtnShow
          addBtn={this.addHandle.bind(this)}
          deleteBtnShow
          deleteBtn={this.deleteHandle.bind(this)}
          exportBtnShow
          importBtnShow
          importBtnUrl="f"
        >
          <MyTable
            columns={columns}
            rowSelection={rowSelection}
           //  dataSource={PublicService.transformArrayData(this.props.dataSource, true, false, this.props.page, this.props.size)}
            dataSource={dataSource}
            scroll={{y: height - 317}}
            pagination={{
              size: config.size,
              pageSize: this.props.size,
              total: this.props.total,
              current: this.props.page,
              showQuickJumper: true,
              onChange: this.onChangePage.bind(this)
            }}
          />
        </Container>
      </div>
    )


  }
}

function mapStateToProps(state) {
  return {
    visible: state.stationRule.isVisible,
    selectedRowKeys: state.stationRule.selectedRows,
    size: state.stationRule.size,
    page: state.stationRule.page,
    total: state.stationRule.total,
    dataSource: state.stationRule.dataSource,
    initData: state.stationRule.initData,
    loading: state.stationRule.loading,
    isEdit: state.stationRule.isEdit,
    treeData: state.stationRule.treeData,
  }
}

export default connect(mapStateToProps)(Right)
